import Ajv from "ajv";
const ajv = new Ajv();

// JSON schema
const schema = {
    type: "object",
    properties: {
        text: {
            type: "string",
        },
        source_lang: {
            type: "string",
            default: "en",
        },
        target_lang: {
            type: "string",
        },
    },
    required: ["text", "target_lang"],
};

// Validator function
const validate = ajv.compile(schema);

// Input data
const inputData = {
    text: "Hello, world!",
    source_lang: 1,
    target_lang: "fr",
};

// Validate input data against the schema
const isValid = validate(inputData);

if (isValid) {
    console.log("Input data is valid");
} else {
    console.error("Input data is invalid");
    console.error(validate.errors);
}
